package com.fort.teachermanagementsys.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fort.teachermanagementsys.dto.ClassQueryDTO;
import com.fort.teachermanagementsys.entity.ClassY;

import com.fort.teachermanagementsys.mapper.ClassManagementMapper;

import com.fort.teachermanagementsys.request.PageParamRequest;
import com.fort.teachermanagementsys.service.ClassManagementService;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ClassManagementServiceImpl  extends ServiceImpl<ClassManagementMapper, ClassY> implements ClassManagementService {

    @Autowired
    private ClassManagementMapper classManagementMapper;


    @Override
    public Boolean addClass(ClassY c) {
        Integer res = classManagementMapper.insert(c);
        return res == 1;
    }

    @Override
    public IPage<ClassY> getClassYPage(Page<ClassY> page, ClassQueryDTO query) {
        // 1. 创建QueryWrapper
        QueryWrapper<ClassY> wrapper = new QueryWrapper<>();
        // 动态添加查询条件
        if (query != null) {
            if (StringUtils.isNotBlank(query.getClassName())) {
                wrapper.like("class_name", query.getClassName());
            }
            if (StringUtils.isNotBlank(query.getCourseName())) {
                wrapper.like("course_name", query.getCourseName());
            }
            if (StringUtils.isNotBlank(query.getTeacher())) {
                wrapper.eq("teacher", query.getTeacher());
            }
            if (StringUtils.isNotBlank(query.getClassTime())) {
                wrapper.eq("class_time", query.getClassTime());
            }
            // Add more conditions as needed
        }

        return classManagementMapper.selectPage(page, wrapper);
    }


}
